package com.oa.jixiao.dao;

import com.oa.jixiao.entity.Assessment;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;


@MapperScan
public interface AssessmentMapper {
    @Delete({
        "delete from assess",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into assess (id, name, ",
        "score, moth, ass_number)",
        "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{score,jdbcType=VARCHAR}, #{moth,jdbcType=INTEGER}, #{assNumber,jdbcType=VARCHAR})"
    })
    int insert(Assessment record);

    int insertSelective(Assessment record);

    @Select({
        "select",
        "id, name, score, moth, ass_number",
        "from assess",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("com.oa.jixiao.dao.AssessmentMapper.BaseResultMap")
    Assessment selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Assessment record);

    @Update({
        "update assess",
        "set name = #{name,jdbcType=VARCHAR},",
          "score = #{score,jdbcType=VARCHAR},",
          "moth = #{moth,jdbcType=INTEGER},",
          "ass_number = #{assNumber,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Assessment record);
    
    
    @Select("select count(id) from assess where moth=#{moth} and ass_number=#{assNumber}")
    int findByNameAndMonth(Assessment record);
    
    @ResultMap("com.oa.jixiao.dao.AssessmentMapper.BaseResultMap")
    @Select("select name ,sum(score) score from assess where moth=#{month} GROUP BY name")
    List<Assessment> totalScore(int month);
}